//
//  VideoListItemCollectionViewCell.m
//  UniversalApp
//
//  Created by 志刚杨 on 2018/2/27.
//  Copyright © 2018年 voidcat. All rights reserved.
//

#import "VideoListItemCollectionViewCell.h"

@implementation VideoListItemCollectionViewCell
{
    UIImageView *videoImage;
    UILabel *nickname;
    QMUIButton *likeImage;//喜欢图片
    QMUIButton *playNumber;//播放图片
    QMUIButton *hasCoin;//付费视频
    QMUIButton *auditing;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
//    self.qmui_shouldShowDebugColor = YES;
//    self.qmui_needsDifferentDebugColor = YES;
    
    //addview
    [self setupUI];
}

-(void)setupUI
{
    videoImage = [[UIImageView alloc] init];
    videoImage.contentMode = UIViewContentModeScaleAspectFill;
    
    nickname = [[UILabel alloc] init];
    nickname.text = ASLocalizedString(@"测试...");
    nickname.font = DEFAULT_FONT(13);
    nickname.textColor = [UIColor whiteColor];
    
    likeImage = [[QMUIButton alloc] init];
    [likeImage setImage:IMAGE_NAMED(@"sd_likeCount") forState:UIControlStateNormal];
    [likeImage setTitle:@"123" forState:UIControlStateNormal];
    [likeImage setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    likeImage.titleLabel.font = DEFAULT_FONT(11);
    
    playNumber = [[QMUIButton alloc] init];
    [playNumber setImage:IMAGE_NAMED(@"sd_playCount") forState:UIControlStateNormal];
    [playNumber setTitle:@"123" forState:UIControlStateNormal];
    [playNumber setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    playNumber.titleLabel.font = DEFAULT_FONT(11);

    nickname.shadowColor = [UIColor blackColor];    //设置文本的阴影色彩和透明度。
    nickname.shadowOffset = CGSizeMake(1.0f, 1.0f);     //设置阴影的倾斜角度。
    
    hasCoin = [[QMUIButton alloc] init];
    hasCoin.titleLabel.font = DEFAULT_FONT(11);
    [hasCoin setImage:[UIImage imageNamed:@"icon_video_label_purchase"] forState:UIControlStateNormal];
//    [hasCoin setTitle:@"收费" forState:UIControlStateNormal];
    
    auditing = [[QMUIButton alloc] init];
    auditing.titleLabel.font = DEFAULT_FONT(11);
//    [auditing setTitle:@"审核中" forState:UIControlStateNormal];
    [auditing setImage:IMAGE_NAMED(@"icon_video_label_auditing") forState:UIControlStateNormal];

    [self addSubview:videoImage];   //视频封面
    [self addSubview:nickname];     //昵称
    [self addSubview:likeImage];   //喜欢数量
    [self addSubview:playNumber]; //播放数量
    [self addSubview:hasCoin]; //播放数量
    [self addSubview:auditing];   //审核提示
    [self setLayout];
}

-(void)setLayout
{
    [videoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [nickname mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self).offset(-30);
        make.left.equalTo(self).offset(10);
        make.height.equalTo(@30);
    }];
    
    [likeImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nickname);
        make.top.equalTo(nickname.mas_bottom).offset(5);
        make.height.equalTo(@15);
    }];
    
    [playNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(likeImage.mas_right).offset(12);
        make.top.equalTo(likeImage);
        make.height.equalTo(@15);
    }];
    
    [hasCoin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-5);
        make.top.equalTo(self).offset(5);
        make.width.equalTo(@35);
        make.height.equalTo(@15);
    }];
    
    [auditing mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(5);
        make.top.equalTo(self).offset(5);
        make.width.equalTo(@40);
        make.height.equalTo(@15);
    }];
}

-(void)setModel:(videoListModel *)model
{
    _model = model;
    if(model.type == 0)
    {
        auditing.hidden = NO;
    }
    else
    {
        auditing.hidden = YES;
    }
    if(KIOSBASE)
    {
        videoImage.image = [[CYCommon sharedCYCommon] getKatongImageWidthID:NSStringFormat(@"%ld",model.uid)];
        nickname.text = ASLocalizedString(@"看一看");
    }
    else
    {
        [videoImage sd_setImageWithURL:[cyurl safeUrl:model.img]];
        nickname.text = model.title;
    }

    if(model.status == 1)
    {
        hasCoin.hidden = YES;
    }
    else
    {
        hasCoin.hidden = NO;
    }
    [likeImage setTitle:NSStringFormat(@"%@",model.follow_num) forState:UIControlStateNormal];
    [playNumber setTitle:NSStringFormat(@"%ld",(long)model.viewed) forState:UIControlStateNormal];
}

@end
